<?php

namespace apiend\modules\dynamic\controllers;

use apiend\components\Controller;
use common\models\mongo\DynamicMessCount;

/**
 * 广场消息
 */
class DynamicmessController extends Controller {
    /**
     * @inheritdoc
     */
    protected function rules() {
        return [
            [
                'allow' => true,
                'roles' => ['@'],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    protected function verbs() {
        return [
            'cnt' => ['GET'],
        ];
    }

    /**
     * 用户统计数量
     * @return array
     */
    public function actionCnt() {
        $dynamicMessCount = DynamicMessCount::findOne(['user_id' => $this->token->user_id]);

        if (!$dynamicMessCount) {
            return ['mess_cnt' => 0];
        }
        return $dynamicMessCount->toArray(['mess_cnt']);

    }

}
